﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;





namespace KaixinRobot
{
    public static class KXWeb
    {
        public static string verifyCode = "";

        public static string Logon( string mail, string pass)
        {
            return HttpHelper._default.Post( "http://www.kaixin001.com/login/login.php", 
                "url=%2F&email=" + HttpHelper.EncodePostData( mail ) + "&password=" + HttpHelper.EncodePostData( pass ));
        }


        public static class House
        {
            public static string Get_Main()
            {
                string content = HttpHelper._default.Get("http://www.kaixin001.com/app/app.php?aid=1062");
                verifyCode = TextParser.GetVerifyCode(content);
                return content;
            }

            public static string Get_Friend(string uid)
            {
                return HttpHelper._default.Get("http://www.kaixin001.com/app/app.php?aid=1062&url=index.php&_lgmode=pri&fuid=" + uid);
            }

            public static string Get_Room( string fuid, string roomid )
            {
                return HttpHelper._default.Get("http://www.kaixin001.com/!house/index.php?fuid=" + fuid + "&roomid=" + roomid);
            }

            public static string Do_Stay(string fuid, string tuid, string roomid)
            {
                return HttpHelper._default.Post("http://www.kaixin001.com/house/stayhouse.php", 
                    "verify=" + verifyCode + "&roomid=" + roomid + "&tuid=" + tuid + "&fuid=" + fuid + "&status=0");
            }

            public static string Do_KickGuest(string uid, string roomid)
            {
                return HttpHelper._default.Post("http://www.kaixin001.com/house/driveaway.php", 
                    string.Format( "verify={0}&tuid={1}&roomid={2}", verifyCode, uid, roomid) );
            }
        }



        public static class Garden
        {
            public enum Action
            { 
                Water = 1,
                Antivermin = 2,
                Antigrass = 3,
                Havest = 4,
                Plough = 5,
                FarmSeed = 6
            }

            public static string Do_Garden(Action act, string fuid, string farmnum, string seedid)
            {
                string ret = "";
                switch (act)
                {
                    case Action.Water:
                        ret = Do_Water(fuid, farmnum);
                        break;

                    case Action.Plough:
                        ret = Do_Plough(fuid, farmnum);
                        break;

                    case Action.Havest:
                        ret = Do_Havest(fuid, farmnum);
                        break;

                    case Action.FarmSeed:
                        ret = Do_FarmSelfSeed(farmnum, seedid);
                        break;

                    case Action.Antivermin:
                        ret = Do_Antivermin(fuid, farmnum);
                        break;

                    case Action.Antigrass:
                        ret = Do_Antigrass(fuid, farmnum);
                        break;

                    default:
                        break;
                }
                return ret;
            }

            public static string baseLink = "http://www.kaixin001.com/!house/!garden/";

            public static string Get_Main()
            {
                string content = HttpHelper._default.Get("http://www.kaixin001.com/!house/garden/index.php");
                verifyCode = TextParser.GetVerifyCode(content);
                return content;
            }

            public static string Get_Config(string uid)
            {
                return HttpHelper._default.Get(baseLink+"/getconf.php?verify=" + verifyCode + "&fuid=" + uid + "&r=" + TextParser.RandomString());
            }

            public static string Get_FriendMature()
            {
                return HttpHelper._default.Get(baseLink+"/getfriendmature.php?verify=" + verifyCode + "&r=" + TextParser.RandomString());
            }

            public static string Do_BuySeed(string seedid)
            {
                return HttpHelper._default.Get(baseLink+"/buyseed.php?verify=" + verifyCode + "&seedid=" + seedid + "&num=1");
            }

            public static string Do_FarmFriendSeed(string fuid, string seedid, string farmnum)
            {
                return HttpHelper._default.Get(baseLink+"/farmseed.php?fuid=" + fuid + "&r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=" + seedid + "&farmnum=" + farmnum);
            }

            private static string Do_FarmSelfSeed(string farmnum, string seedid)
            {
                    return HttpHelper._default.Post(baseLink+"/farmseed.php",
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=" + seedid + "&fuid=0&farmnum=" + farmnum);
            }

            private static string Do_Water(string fuid, string farmnum)
            {
                return HttpHelper._default.Post(baseLink+"/water.php", 
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=0&fuid=" + fuid + "&farmnum=" + farmnum);
            }

            private static string Do_Antivermin(string fuid, string farmnum)
            {
                return HttpHelper._default.Post(baseLink+"/antivermin.php", 
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=0&fuid=" + fuid + "&farmnum=" + farmnum);
            }

            private static string Do_Antigrass(string fuid, string farmnum)
            {
                return HttpHelper._default.Post(baseLink+"/antigrass.php", 
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=0&fuid=" + fuid + "&farmnum=" + farmnum);
            }

            private static string Do_Havest(string fuid, string farmnum)
            {
                return HttpHelper._default.Post(baseLink+"/havest.php", 
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=0&fuid=" + fuid + "&farmnum=" + farmnum);
            }

            private static string Do_Plough(string fuid, string farmnum)
            {
                return HttpHelper._default.Post(baseLink+"/plough.php", 
                    "r=" + TextParser.RandomString() + "&verify=" + verifyCode + "&seedid=0&fuid=" + fuid + "&farmnum=" + farmnum);
            }

            public static string Do_SendFruit(string touid, string seedid, string fruitnum)
            {
                return HttpHelper._default.Post(baseLink+"/presentfruit.php", 
                    "num=" + fruitnum + "&pmsg=" + "%3A%2D%29" + "&anon=0&verify=" + verifyCode + "&seedid=" + seedid + "&touid=" + touid);
            }

            public static string Do_SellFruit()
            {
                return HttpHelper._default.Get(baseLink+"/sellfruit.php?verify=" + verifyCode + "&all=1&seedid=0&num=1");
            }

            public static string Get_MyGranary()
            {
                return HttpHelper._default.Get(baseLink+"/mygranary.php?verify=" + verifyCode + "&r=" + TextParser.RandomString());
            }

            public static string Get_MyFruitInfo(string seedid)
            {
                return HttpHelper._default.Get(baseLink+"/myfruitinfo.php?seedid=" + seedid + "&verify=" + verifyCode + "&r=" + TextParser.RandomString());
            }

            public static string Get_Seedinfo(string seedid)
            {
                return HttpHelper._default.Get(baseLink+"/seedinfo.php?seedid=" + seedid + "&verify=" + verifyCode + "&r=" + TextParser.RandomString());
            }

            public static string Get_MySeedList()
            {
                return HttpHelper._default.Get(baseLink+"/myseedlist.php?verify=" + verifyCode + "&page=1&r=" + TextParser.RandomString());
            }
            
        }



        public static class HouseJob
        {
            public static string Get_JobList()
            {
                return HttpHelper._default.Get("http://www.kaixin001.com/!house/jobslist.php");
            }

            public static string Do_Job(string jobid)
            {
                return HttpHelper._default.Get("http://www.kaixin001.com/house/dojob.php?verify=" + verifyCode + "&petid=" + jobid);
            }        
        }


    }





}
